<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
	<title>短信发送区域管理地图</title>
	<style type="text/css">
		body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
		#result {width:100%;font-size:12px;}
	</style>
	<script src="../../layui/layui.js"></script>
	<script src="../../js/util.js"></script>
	<link rel="stylesheet" type="text/css" href="../../css/mapstyle.css">
	<link rel="stylesheet" type="text/css" href="../../css/xcConfirm.css"/>
	<script src="../../js/jquery-1.9.1.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../js/xcConfirm.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript" src="../../js/map2/apimap.js"></script>
	<!--加载鼠标绘制工具-->
	<script type="text/javascript" src="../../js/map2/DrawingManager_min.js"></script>
	<link rel="stylesheet" href="../../css/map2/DrawingManager_min.css" />


<!-- <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=nSGoPNzNrehEaGBst1TZzklH"></script>
	加载鼠标绘制工具
	<script type="text/javascript" src="http://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.js"></script>
	<link rel="stylesheet" href="http://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.css" /> -->
</head>
<body>
	<div id="allmap"></div>
	<div id="loadingDiv" class="load-white-bg hide">
	<span class="qloading">正在加载...</span>
	</div> 
	<!-- <input type="button" value="获取绘制的覆盖物个数" onclick="alert(overlays.length)"/>
	<input type="button" value="清除所有覆盖物" onclick="clearAll()"/>
	<input type="button" value="保存" onclick="onSave()"/> -->
</body>
</html>
<script type="text/javascript">

var map = null;
var cityId;
var resultRegionValue;//结果区域图形值 1: a,b   2:经度，纬度#半径   3:4: 经度，纬度#经度，纬度
var resultRegionType;//结果区域图形 1行政区域组合 2圆形 3矩形 4 多边形
var cityName="";//城市区县名称
var initialFunc = function(){
    // 百度地图API功能
	map = new BMap.Map("allmap",{minZoom:8,maxZoom:18}); // 创建Map实例,设置地图允许的最小/大级别
	map.enableScrollWheelZoom(true);//开启鼠标滚轮缩放  
	/* if(isHaveJW!=""){
		map.centerAndZoom(isHaveJW,13); // 初始化地图,设置中心点坐标和地图级别
	}else{
		map.centerAndZoom(cityJW,13); // 初始化地图,设置中心点坐标和地图级别
	}
	map.enableScrollWheelZoom(true);//开启鼠标滚轮缩放  */
}
var markers = [];//全省基站点
var cityJW ;
var isHaveJW="";//获取是否已有圈画过的图形，如有则定位到图形
var scopeId;//获取范围编码scopeId;
$(document).ready(function() {
	//getLogin();
    cityId=getUrlParam("cityId");
    scopeId=getUrlParam("scopeId");
    //console.info(scopeId);
    //scopeId='2019110011';
    getTypeAndValue(scopeId);
    cityJW= getJWByCityId(cityId);//获取对应地市大大致经纬度
    cityName=decodeURI(getUrlParam("cityName"));
    //getBoundary();
    //resultRegionType=getUrlParam("regionType");
    //resultRegionValue=getUrlParam("regionTypeValue");
    //isHaveJW = getJWIsHave(resultRegionValue);
    //initialFunc();
    //getData();
    //getTuxing();
});

function getBoundary(){       
		var bdary = new BMap.Boundary();
		bdary.get(cityName, function(rs){       //获取行政区域
			//map.clearOverlays();        //清除地图覆盖物       
			var count = rs.boundaries.length; //行政区域的点有多少个
			if (count === 0) {
				alert('未能获取当前输入行政区域');
				return ;
			}
          	var pointArray = [];
			for (var i = 0; i < count; i++) {
				var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 3, strokeColor: "#000000",fillColor:"#ffffff",fillOpacity:0.01}); //建立多边形覆盖物
				//var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 2, strokeColor: "#ff0000"}); //建立多边形覆盖物
				map.addOverlay(ply);  //添加覆盖物
				pointArray = pointArray.concat(ply.getPath());
			}    
			map.setViewport(pointArray);    //调整视野           
		});   
	}

function getLogin(){
	    var url="/login";
	    $.ajax({
	        url:url,
	        type:"post",
	        success:function(data){
	            var result=data.data;
	            if(result!=null&&result!=""){
	            		console.info("登录成功！");
	            }
	        }
	    });
}


	function getTypeAndValue(scopeId) {
		var param = {
			scopeId : scopeId
		}
		var url = "/smsArea/qxjScopeQry";
		$.ajax({
			url : url,
			data : param,
			type : "post",
			beforeSend : function() {
				if (scopeId == "" || scopeId == null) {
					console.info("查询失败, 范围编码缺失");
					cityJW= getJWByCityId(14);
					initialFunc();
					window.wxc.xcConfirm("查询失败, 范围编码缺失", window.wxc.xcConfirm.typeEnum.info);
					return false;
				}
			},
			success : function(obj) {
				//$("#loadingDiv").hide();
				if (obj.data != null&&obj.data!='') {
					resultRegionType = obj.data.scopeType;
					resultRegionValue = obj.data.longAndLats;
					//isHaveJW = getJWIsHave(resultRegionValue);
					initialFunc();
					getBoundary();
					getTuxing();
					
				}else{
					cityJW= getJWByCityId(14);
					initialFunc();
					window.wxc.xcConfirm("暂无范围信息！", window.wxc.xcConfirm.typeEnum.info);
				}
			},
			error : function() {
				layer.close(index);
				layer.msg('系统异常，请联系管理员处理!');
			}
		});
	}

	function getJWIsHave(resultRegionValue){
	//console.info("resultRegionValue===="+resultRegionValue)
	var array = resultRegionValue.split('|');
	if(array.length>1){
		var JW = array[0].split(',');
		var JD = JW[0];
		var WD = JW[1];
		return new BMap.Point(JD,WD);
	}else{
		return "";
	}
	
}

function getData(){
    var url="/smsArea/findAllStation?cityId="+getUrlParam("cityId")+"&countyId=&longitudeMin=&longitudeMax=&latitudeMin=&latitudeMax=";
    $.ajax({
        url:url,
        type:"post",
        success:function(data){
            $.each(data,function(i,d){
                markers[i]={position:{lat:d.latitude,lng:d.longitude},stationid:d.stationMarkId,stationname:d.stationMarkName};
            });
        }
    });
}
//获取图形
function getTuxing(){
	/* if(resultRegionType==2){
	    var arr = resultRegionValue.split('+');
	    var xy=arr[0].split(',');
		var c = new BMap.Point(xy[0],xy[1]); //圆心 
		var circle = new BMap.Circle(c, arr[1]);//测试圆
		map.clearOverlays();
		map.addOverlay(circle);
	}else if(resultRegionType==3){
		var arr = resultRegionValue.split('+');
		var xy1=arr[0].split(',');
		var xy2=arr[1].split(',');
		var xy3=arr[2].split(',');
		var xy4=arr[3].split(',');
		var pts = [];
	    //bds的四个脚点坐标
	    var leftTop = new BMap.Point(xy1[0], xy1[1]);
	    var rightTop = new BMap.Point(xy2[0], xy2[1]);
	    var leftBottom = new BMap.Point(xy3[0], xy3[1]);
	    var rightBottom = new BMap.Point(xy4[0], xy4[1]);
	    pts.push(leftTop);
	    pts.push(rightTop);
	    pts.push(rightBottom);
	    pts.push(leftBottom);
	    var rect = new BMap.Polygon(pts);
	    map.addOverlay(rect);//添加测试矩形   
	}else  */if(resultRegionType==1||resultRegionType==2){
	    var arr = resultRegionValue.split('|');
	    var pts = [];
	    for(var i=0;i<arr.length;i++){
	        var pt = new BMap.Point(arr[i].split(',')[0], arr[i].split(',')[1]);
	    	pts.push(pt);
	    }
	    
	    var ply = new BMap.Polygon(pts);
	    //map.clearOverlays();
	    map.addOverlay(ply);  
	}else if(resultRegionType==3){
		var arr = resultRegionValue.split('|');
	    var xy=arr[0].split(',');
		var c = new BMap.Point(xy[0],xy[1]); //圆心 
		var circle = new BMap.Circle(c, arr[1]);//测试圆
		map.clearOverlays();
		map.addOverlay(circle);
	}

}



// 苏州   11淮安   12宿迁   13南京   14连云港   15徐州   16常州   17镇江   18无锡   19南通   20泰州   21 盐城   22 扬州   23
function getJWByCityId(cityId){
    if(cityId=="11"){
        return new BMap.Point(120.58,31.30);
    }else if(cityId=="12"){
        return new BMap.Point(119.02,33.62);
    }else if(cityId=="13"){
        return new BMap.Point(118.28,33.97);
    }else if(cityId=="14"){
        return new BMap.Point(118.78,32.04);
    }else if(cityId=="15"){
        return new BMap.Point(119.22,34.60);
    }else if(cityId=="16"){
        return new BMap.Point(117.18,34.27);
    }else if(cityId=="17"){
        return new BMap.Point(119.95,31.78);
    }else if(cityId=="18"){
        return new BMap.Point(119.45,32.20);
    }else if(cityId=="19"){
        return new BMap.Point(120.30,31.57);
    }else if(cityId=="20"){
        return new BMap.Point(120.88,31.98);
    }else if(cityId=="21"){
        return new BMap.Point(119.92,32.45);
    }else if(cityId=="22"){
        return new BMap.Point(120.15,33.35);
    }else if(cityId=="23"){
        return new BMap.Point(119.40,32.40);
    }else{
        return new BMap.Point(118.875, 32.825);
    }
}


</script>
